<?php

class DemoController extends Controller
{
	public $layout = '//layouts/demo';
	
	public function actionIndex()
	{
		$this->render('index');
	}
	
	public function actionFormtest()
	{
// 		$model = new DemoForm;
// 		$form = new CForm('theme.views.demo.demoForm', $model);
// 		if($form->submitted('login') && $form->validate())
// 			$this->redirect(array('demo/index'));
// 		else
// 			$this->render('formtest', array('form'=>$form));
		
// 		$form = "hello";
// 		$this->render('formtest', array('form'=>$form));
		
		$model = new DemoForm;
		if(isset($_POST['ajax'])) {
			$ret = array(
				'code' => 1,
				'message' => '已经被注册'
			);
			$this->response($ret);
		}
		
		if(isset($_POST['DemoForm']))
		{
			$model->attributes=$_POST['DemoForm'];
			// validate user input and redirect to the previous page if valid
// 			if($model->validate() && $model->login())
// 				$this->redirect(Yii::app()->user->returnUrl);
			
			header('Content-type: application/json');
			var_dump($_POST);
			echo '</br>';
			var_dump($model);
			//$this->response('');
			Yii::app()->end();
		}
		
		$this->render('formtest',array('model'=>$model));
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}